package com.api.oa.controller;


import com.api.oa.model.entity.YQVideo;
import com.api.oa.services.YQVideoService;
import com.api.shopapi.controller.BaseController;
import com.api.shopapi.entity.MyResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/yq/yQVideo")
public class YQVideoController extends BaseController {

        @Autowired
        private YQVideoService iYQVideoService;

        @RequestMapping(value = "/add", method = RequestMethod.POST)
        public MyResult Add(@RequestBody YQVideo entity) {
            try {
                 return iYQVideoService.add(entity) == 1 ? success(entity) : failed("操作失败");
            } catch (Exception e) {
                 return anomalous(getExceptionMsg(e));
            }

        }


        @RequestMapping(value = "/remove/{id}", method = RequestMethod.POST)
        public MyResult remove(@PathVariable Long id) {
            try {
                iYQVideoService.remove(id);
                return success("删除成功!");
            } catch (Exception e) {
                return anomalous(getExceptionMsg(e));
            }

        }


        @RequestMapping(value = "/update", method = RequestMethod.POST)
        public MyResult update(@RequestBody YQVideo entity) {
            try {
                return iYQVideoService.update(entity) == 1 ?  success("操作成功") : failed("操作失败");
            } catch (Exception e) {
                return anomalous(getExceptionMsg(e));
            }

        }


        @RequestMapping(value = "/list", method = RequestMethod.GET)
        public MyResult list(@RequestParam(defaultValue = "0") Integer pageIndex,@RequestParam(defaultValue = "20") Integer pageSize,
                             @RequestParam(required = false) String insCode, @RequestParam(required = false) String keyWord) {
            try {
                return success(iYQVideoService.list(insCode,keyWord,pageIndex,pageSize));
            } catch (Exception e) {
                return anomalous(getExceptionMsg(e));
            }
        }


        @RequestMapping(value = "/one/{id}", method = RequestMethod.GET)
        public MyResult one(@PathVariable Long id) {
            try {
                return success(id == null ? null :iYQVideoService.one(id));
            } catch (Exception e) {
                return anomalous(getExceptionMsg(e));
            }
        }


}
